package cs757;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableColumn;

public class MainGUI extends JFrame {

	private static final long serialVersionUID = 8089105977217603872L;
	private JPanel contentPane;
	private JTable table;
	private JScrollPane scrollPane;
	private final ButtonGroup buttonGroup = new ButtonGroup();

	private JRadioButton rdbtnID;
	private JRadioButton rdbtnFunding;
	private JButton btnAdd;
	private JButton btnDelete;
	private JButton btnEdit;
	private JLabel lblWelcome;
	private Query currentQuery;
	private JButton btnByDept;
	private JLabel lblProjects;
	private JLabel lblOrderBy;
	private JLabel lblView;
	private JButton btnMostFunded;
	
	/**
	 * Current query type (i.e. what table is currently shown in the results)
	 */
	private enum Query{Students, Professors, Projects};

	//Database connection
	private DatabaseConnector dbConn;
	
	//user's ID
	private String userID;

	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainGUI frame = new MainGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainGUI() {
		setTitle("Query University Database");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 773, 561);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		lblWelcome = new JLabel("Welcome "+userID+"!");
		lblWelcome.setFont(new Font("Tahoma", Font.BOLD, 19));
		
		JButton btnViewStudents = new JButton("View Students");
		btnViewStudents.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enableProjectOptions(false);
				try {
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.STUDENTS_QUERY, 
							DatabaseConnector.columnNamesStudents.size());
					refreshResultsTable(resultData, DatabaseConnector.columnNamesStudents);
					currentQuery = Query.Students;
					btnEdit.setEnabled(false);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.STUDENTS_QUERY,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		JButton buttonViewProfessors = new JButton("View Professors");
		buttonViewProfessors.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enableProjectOptions(false);
				try {  
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROFESSORS_QUERY, 
							DatabaseConnector.columnNamesProfessors.size());
					refreshResultsTable(resultData, DatabaseConnector.columnNamesProfessors);
					currentQuery = Query.Professors;
					btnEdit.setEnabled(false);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROFESSORS_QUERY,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		JButton buttonViewProjects = new JButton("View Projects");
		buttonViewProjects.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enableProjectOptions(true);
				try {  
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_QUERY, 
							DatabaseConnector.columnNamesProjects.size());
					refreshResultsTable(resultData, DatabaseConnector.columnNamesProjects);
					currentQuery = Query.Projects;
					btnEdit.setEnabled(true);
					rdbtnID.setSelected(true);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_QUERY,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		JButton buttonEncryption = new JButton("Encryption");
		buttonEncryption.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
					launchEncryptionGUI();
			}
		});
		
		JLabel lblResults = new JLabel("Results:");
		lblResults.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		scrollPane = new JScrollPane();
		
		lblOrderBy = new JLabel("Order by:");
		lblOrderBy.setEnabled(false);
		
		rdbtnID = new JRadioButton("ID");
		rdbtnID.setSelected(true);
		rdbtnID.setEnabled(false);
		buttonGroup.add(rdbtnID);
		rdbtnID.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enableProjectOptions(true);
				try { 
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_QUERY_ORDER_ID, 
							DatabaseConnector.columnNamesProjects.size());
					refreshResultsTable(resultData, DatabaseConnector.columnNamesProjects);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_QUERY_ORDER_ID,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		rdbtnFunding = new JRadioButton("Funding");
		rdbtnFunding.setEnabled(false);
		buttonGroup.add(rdbtnFunding);
		rdbtnFunding.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enableProjectOptions(true);
				try {  
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_QUERY_ORDER_BUDGET, 
							DatabaseConnector.columnNamesProjects.size());
					refreshResultsTable(resultData, DatabaseConnector.columnNamesProjects);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_QUERY_ORDER_BUDGET,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		btnAdd = new JButton("Add");
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				showAddDialog();
			}
		});
		
		btnDelete = new JButton("Delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				deleteRecord();
			}
		});
		
		btnEdit = new JButton("Edit");
		btnEdit.setEnabled(false);
		btnEdit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int rowIndex = table.getSelectedRow();
				if (rowIndex >=0){

					DlgEditProject editProject = new DlgEditProject();
					editProject.setModal(true);
					editProject.setConn(dbConn);

					String recordKey = (String)table.getValueAt(rowIndex, 0);

					if (dbConn.isUserAProjectManager(recordKey)){
						editProject.setRecordID(recordKey);
						editProject.populateStudentList();
						editProject.populateProfessorList();
						String fundingValue = (String)table.getValueAt(rowIndex, 4);
						editProject.setTextFieldFundingValue(fundingValue);
						editProject.setVisible(true);
						if (editProject.isOk() == true){
							try { 
								Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_QUERY, 
										DatabaseConnector.columnNamesProjects.size());
								refreshResultsTable(resultData, DatabaseConnector.columnNamesProjects);
							} catch (SQLException e) {
								JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_QUERY,
										"Error In Query", JOptionPane.ERROR_MESSAGE);
							}
						}
						rdbtnID.setSelected(true);
					}
					else {
						JOptionPane.showMessageDialog(null, "You must be project manager to edit a project.",
								"Restricted", JOptionPane.ERROR_MESSAGE);
					}
				}
				else {
					JOptionPane.showMessageDialog(null, "Please select a row in the results table.",
							"Please select a record", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		
		btnMostFunded = new JButton("Most funded");
		btnMostFunded.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try { 
					Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_MOST_FUNDED, 2);
					JOptionPane.showMessageDialog(null, "Most funded project is pid:"+resultData.get(0).get(0)+
							" with funding:$"+resultData.get(0).get(1),
							"Result", JOptionPane.INFORMATION_MESSAGE);
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_MOST_FUNDED,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btnMostFunded.setEnabled(false);
		
		lblView = new JLabel("View:");
		lblView.setEnabled(false);
		
		btnByDept = new JButton("By dept.");
		btnByDept.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try { 
					Vector<Vector<Object>> departments = dbConn.executeQuery(DatabaseConnector.DEPT_ID_QUERY, 2);
					ArrayList<Object> depts = new ArrayList<Object>();
					for (Vector<Object> rows:departments){
						depts.add(rows.get(0)+" - "+rows.get(1));
					}
					Object[] deptOptions = depts.toArray();
					String choice = (String)JOptionPane.showInputDialog(
		                    null,
		                    "Choose a department:",
		                    "Select department",
		                    JOptionPane.PLAIN_MESSAGE,
		                    null,
		                    deptOptions,
		                    deptOptions[0]);
					
					if ((choice != null) && (choice.length() > 0)) {
						String deptNum = choice.substring(0, choice.indexOf('-'));
						Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_BY_DEPARTMENT+deptNum, 
								DatabaseConnector.columnNamesProjectsByDepartment.size());
						refreshResultsTable(resultData, DatabaseConnector.columnNamesProjectsByDepartment);
					}
				} catch (SQLException e) {
					JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_BY_DEPARTMENT,
							"Error In Query", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btnByDept.setEnabled(false);
		
		lblProjects = new JLabel("Projects Options");
		lblProjects.setEnabled(false);
		lblProjects.setFont(new Font("Tahoma", Font.BOLD, 12));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(btnViewStudents, GroupLayout.PREFERRED_SIZE, 177, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(buttonViewProfessors, GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(buttonViewProjects, GroupLayout.PREFERRED_SIZE, 184, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(buttonEncryption, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(311)
							.addComponent(lblWelcome))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 584, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
											.addComponent(lblView)
											.addComponent(btnMostFunded, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
											.addComponent(btnByDept, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
										.addComponent(lblProjects)
										.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
											.addComponent(btnAdd, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
											.addComponent(btnEdit, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
											.addComponent(rdbtnFunding)
											.addComponent(rdbtnID)
											.addComponent(lblOrderBy)
											.addComponent(btnDelete))))
								.addComponent(lblResults))))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblWelcome))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(56)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(btnViewStudents, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
								.addComponent(buttonViewProfessors, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
								.addComponent(buttonViewProjects, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
								.addComponent(buttonEncryption, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblResults)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 372, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblProjects)
									.addGap(66)
									.addComponent(lblView)
									.addGap(4)
									.addComponent(btnMostFunded)
									.addGap(5)
									.addComponent(btnByDept))))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(39)
							.addComponent(lblOrderBy)
							.addGap(3)
							.addComponent(rdbtnID)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(rdbtnFunding)
							.addGap(142)
							.addComponent(btnAdd)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnDelete)
							.addGap(7)
							.addComponent(btnEdit)
							.addPreferredGap(ComponentPlacement.RELATED)))
					.addGap(78))
		);
		
		table = new JTable();
		scrollPane.setViewportView(table);
		contentPane.setLayout(gl_contentPane);
		
		enableProjectOptions(false);
		enableResultButtons(false);
	}
	
	/**
	 * Bulk setting of buttons/fiels in the GUI that only apply to certain queries
	 * @param enabled
	 */
	private void enableProjectOptions(boolean enabled){
		lblProjects.setEnabled(enabled);
		lblView.setEnabled(enabled);
		lblOrderBy.setEnabled(enabled);
		if (DatabaseConnector.ADMIN_USER_NAME.equals(userID)) {
			rdbtnFunding.setEnabled(enabled);
			rdbtnID.setEnabled(enabled);
			btnByDept.setEnabled(enabled);
			btnMostFunded.setEnabled(enabled);
		}

	}
	
	/**
	 * Enable add/delete/edit buttons 
	 * @param enabled
	 */
	private void enableResultButtons(boolean enabled){
		btnAdd.setEnabled(enabled);
		btnDelete.setEnabled(enabled);
		if(currentQuery == Query.Projects){
			btnEdit.setEnabled(enabled);
		}

	}
	
	/**
	 * Display the GUI
	 * @param dbConn
	 */
	public void launch(DatabaseConnector dbConn){
		this.dbConn = dbConn;
		setVisible(true);
	}
	
	/**
	 * Iterate through a two-dimensional vector of query results and display the 
	 * data in a table.
	 * @param results
	 * @param columnNames
	 */
	private void refreshResultsTable(Vector<Vector<Object>> results, Vector<String> columnNames){
		table = new JTable(results, columnNames){
		    public boolean isCellEditable(int rowIndex, int vColIndex) {
		        return false;
		    }
		};	
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		TableColumn column = null;
		for (int i = 0; i < columnNames.size(); i++) {
		    column = table.getColumnModel().getColumn(i);
		    column.setPreferredWidth(110); 
		}
		scrollPane.setViewportView(table);
		
		enableResultButtons(true);
	}
	
	/**
	 * Delete a record from the database
	 * Query used depends on what table (students, professors, projects) is 
	 * currently displayed.
	 */
	private void deleteRecord() {
		int rowIndex = table.getSelectedRow();
		if (rowIndex >= 0){
			String recordKey = (String)table.getValueAt(rowIndex, 0);

			Vector<String> columnNames = null;
			String deleteQuery = "";
			String refreshQuery ="";

			try { 
				switch (currentQuery){
				case Students:
					if (userID.equals(DatabaseConnector.ADMIN_USER_NAME)) {
						deleteQuery = DatabaseConnector.DELETE_STUDENT_ADVISEE_QUERY;
						refreshQuery = DatabaseConnector.STUDENTS_QUERY;
						columnNames = DatabaseConnector.columnNamesStudents;
					}
					else{
						JOptionPane.showMessageDialog(null, "You must be an admin to delete students.",
								"Restricted", JOptionPane.ERROR_MESSAGE);
						return;
					}
					break;
				case Professors:
					if (userID.equals(DatabaseConnector.ADMIN_USER_NAME)) {
						deleteQuery = DatabaseConnector.DELETE_PROFESSOR_QUERY;
						refreshQuery = DatabaseConnector.PROFESSORS_QUERY;
						columnNames = DatabaseConnector.columnNamesProfessors;
					}
					else{
						JOptionPane.showMessageDialog(null, "You must be an admin to delete professors.",
								"Restricted", JOptionPane.ERROR_MESSAGE);
						return;
					}
					break;
				case Projects:
					if (dbConn.isUserAProjectManager(recordKey)){
						deleteQuery = DatabaseConnector.DELETE_PROJECT_QUERY;
						refreshQuery = DatabaseConnector.PROJECTS_QUERY;
						columnNames = DatabaseConnector.columnNamesProjects;

						String deleteQuery2 = DatabaseConnector.DELETE_GROUP_MEMBER_PROFESSOR_MANAGER;
						dbConn.executeDelete(deleteQuery2, recordKey);
					}
					else{
						JOptionPane.showMessageDialog(null, "You must be an project manager to delete projects.",
								"Restricted", JOptionPane.ERROR_MESSAGE);
						return;
					}
					break;
				}

				dbConn.executeDelete(deleteQuery, recordKey);
				
				if (currentQuery == Query.Students){
					//secondary delete action
						deleteQuery = DatabaseConnector.DELETE_STUDENT_QUERY;
						dbConn.executeDelete(deleteQuery, recordKey);
				}

				Vector<Vector<Object>> resultData = dbConn.executeQuery(refreshQuery, columnNames.size());
				refreshResultsTable(resultData, columnNames);
				rdbtnID.setSelected(true);
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, "Error deleting from database.\nQuery:"+deleteQuery,
						"Error In Query", JOptionPane.ERROR_MESSAGE);
			}
		}
		else{
			JOptionPane.showMessageDialog(null, "Please select a row in the results table.",
					"Please select a record", JOptionPane.INFORMATION_MESSAGE);
		}
	}
	
	/**
	 * Show the dialog for adding a student/professor/project
	 * Actual dialog shown depends on what table (students, professors, projects) is 
	 * currently displayed. 
	 */
	private void showAddDialog(){
		switch(currentQuery){
		case Students:
			if (userID.equals(DatabaseConnector.ADMIN_USER_NAME)) {
				DlgAddStudent addStudent = new DlgAddStudent();
				addStudent.setModal(true);
				addStudent.setConn(dbConn);
				addStudent.populateMajorComboBox();
				addStudent.populateAdvisorComboBox();
				addStudent.setVisible(true);
				if (addStudent.isOk() == true){
					try {  
						Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.STUDENTS_QUERY, 
								DatabaseConnector.columnNamesStudents.size());
						refreshResultsTable(resultData, DatabaseConnector.columnNamesStudents);
					} catch (SQLException e) {
						JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.STUDENTS_QUERY,
								"Error In Query", JOptionPane.ERROR_MESSAGE);
					}
				}		
			}
			else{
				JOptionPane.showMessageDialog(null, "You must be an admin to add students.",
						"Restricted", JOptionPane.ERROR_MESSAGE);
			}
			break;
		case Professors:
			if (userID.equals(DatabaseConnector.ADMIN_USER_NAME)) {
				DlgAddProfessor addProfessor = new DlgAddProfessor();
				addProfessor.setModal(true);
				addProfessor.setConn(dbConn);
				addProfessor.populateComboBox();
				addProfessor.setVisible(true);
				if (addProfessor.isOk() == true){
					try {  
						Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROFESSORS_QUERY, 
								DatabaseConnector.columnNamesProfessors.size());
						refreshResultsTable(resultData, DatabaseConnector.columnNamesProfessors);
					} catch (SQLException e) {
						JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROFESSORS_QUERY,
								"Error In Query", JOptionPane.ERROR_MESSAGE);
					}
				}	
			}
			else{
				JOptionPane.showMessageDialog(null, "You must be an admin to add professors.",
						"Restricted", JOptionPane.ERROR_MESSAGE);
			}
			break;
		case Projects:
			if (dbConn.isUserAProfessor()){
				DlgAddProject addProject = new DlgAddProject();
				addProject.setModal(true);
				addProject.setConn(dbConn);
				addProject.setMainGUI(this);
				addProject.setVisible(true);
				if (addProject.isOk() == true){
					try {  
						Vector<Vector<Object>> resultData = dbConn.executeQuery(DatabaseConnector.PROJECTS_QUERY, 
								DatabaseConnector.columnNamesProjects.size());
						refreshResultsTable(resultData, DatabaseConnector.columnNamesProjects);
					} catch (SQLException e) {
						JOptionPane.showMessageDialog(null, "Error querying database.\nQuery:"+DatabaseConnector.PROJECTS_QUERY,
								"Error In Query", JOptionPane.ERROR_MESSAGE);
					}
					rdbtnID.setSelected(true);
				}		
			}
			else{
				JOptionPane.showMessageDialog(null, "You must be an professor to add projects.",
						"Restricted", JOptionPane.ERROR_MESSAGE);
			}
			break;
		}
	}

	/**
	 * @return the userID
	 */
	public String getUserID() {
		return userID;
	}

	/**
	 * @param userID the userID to set
	 */
	public void setUserID(String userID) {
		this.userID = userID;
		lblWelcome.setText("Welcome "+userID+"!");
	}
	
	/**
	 * Launch encryption GUI for encryption demonstration
	 */
	private void launchEncryptionGUI() {
		EncryptionGUI encryptionGUI = new EncryptionGUI();
		encryptionGUI.launch(dbConn);
		
	}
}
